package com.lzb.musicplayer.dialog;

import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ToastUtils;
import com.lzb.basic.dialog.BaseSmartDialog;
import com.lzb.musicplayer.R;
import com.lzb.musicplayer.databinding.DialogRenamePlaylistBinding;


public class RenamePlaylistDialog extends BaseSmartDialog<DialogRenamePlaylistBinding> implements View.OnClickListener {

    private String text;

    public void setText(String text) {
        this.text = text;
    }

    public RenamePlaylistDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected boolean canceledOnTouchOutside() {
        return true;
    }

    @Override
    protected int getGravity() {
        return Gravity.CENTER;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_rename_playlist;
    }

    @Override
    protected void initView(View view) {
        mDataBinding.tvCancel.setOnClickListener(this);
        mDataBinding.tvConfirm.setOnClickListener(this);

        if (!TextUtils.isEmpty(text)){
            mDataBinding.etName.setText(text);
        }
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.tvCancel) {
            dismiss();
        } else if (id == R.id.tvConfirm) {
            String name = mDataBinding.etName.getText().toString();
            if (TextUtils.isEmpty(name)) {
                ToastUtils.showShort(getContext().getString(R.string.please_input_name));
                return;
            }
            dismiss();
            if (listener != null) {
                listener.clickConfirm(name);
            }
        }
    }

    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void clickConfirm(String text);
    }
}
